qinglan.Canvas.EventCollection = qinglan.Canvas.Class(function() {}).statics({
	keyMap: {
		'backspace': 8,
		'tab': 9,
		'enter': 13,
		
		'shiftKey': 16,
		'ctrlKey': 17,
		'altKey': 18,
		
		'esc': 27,
		'blank': 32,

		'up': 38,
		'down': 40,
		'left': 37,
		'right': 39,

		

		'0': 48,
		'1': 49,
		'2': 50,
		'3': 51,
		'4': 52,
		'5': 53,
		'6': 54,
		'7': 55,
		'8': 56,
		'9': 57,
		
		'a': 65,
		'b': 66,
		'c': 67,
		'd': 68,
		'e': 69,
		'f': 70,
		'g': 71,
		'h': 72,
		'i': 73,
		'j': 74,
		'k': 75,
		'l': 76,
		'm': 77,
		'n': 78,
		'o': 79,
		'p': 80,
		'q': 81,
		'r': 82,
		's': 83,
		't': 84,
		'u': 85,
		'v': 86,
		'w': 87,
		'x': 88,
		'y': 89,
		'z': 90,

		'~': 192,
		'-': 189,
		'_': 189,
		'+': 187,
		'=': 187,
		'{': 219,
		'[': 219,
		'}': 221,
		']': 221,
		'|': 220,
		':': 186,
		';': 186,
		'"': 222,
		'<': 188,
		'>': 190,
		'?': 191

	},
	handleList: {},
	keydownMap: {},
	handleId: 0,
	fireEvent: function(e,type){
		if (e.keyCode == 32 || e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40) {qinglan.Event.preventDefault(e);}
		var handleList = qinglan.Canvas.EventCollection.handleList[type];
		qinglan.Object.each(handleList,function(handle){
			('keydown' == type) && (qinglan.Canvas.EventCollection.keydownMap[e.keyCode] = true);
			('keyup' == type) && (qinglan.Canvas.EventCollection.keydownMap[e.keyCode] = false);
			var keymap = ('keydown' == type || 'keyup' == type || 'keypress' == type ) ? qinglan.Canvas.EventCollection.keyMap : {};
			if(handle.condition.call(handle,e,keymap)){
				handle.callback.call(handle,e,keymap);
			}
		});
	},
	on: function(sprite, type, fn, condition){
		var EventCollection = qinglan.Canvas.EventCollection;
		!EventCollection.handleList[type] && (EventCollection.handleList[type]={});
		var eHandle = new qinglan.Canvas.EventHandle((sprite.id + EventCollection.handleId++), sprite, fn, condition);
		EventCollection.handleList[type][eHandle.id] = eHandle;
		return eHandle.id;
	},
	init: function(ele){
 		var ele = ele || document || window;
		qinglan.Array.each(['click', 'mouseDown', 'mouseUp', 'mouseOver',
					'mouseMove', 'mouseOut', 'keyDown',
					'keyPress', 'keyUp'], function(value) {
				qinglan.Event.on(ele,value.toLocaleLowerCase(),function(e){
					qinglan.Canvas.EventCollection.fireEvent(e,e.type);
				});
			});
	}
});

qinglan.Canvas.EventCollection.init();
